using System;
using InfoJetSoft.Service.Worker;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.ManagedCode
{
	/// <summary>
	/// Summary description for SharepointListAdapter.
	/// </summary>
	public class SharepointListAdapter : Microsoft.Office.Interop.InfoPath.SemiTrust.SharepointListAdapterObject
	{

		private InfoJetSoft.Service.Entity.Form form = null;
		private InfoJetSoft.Service.Entity.DataSPListAdapter spListAdapter = null;

		public SharepointListAdapter( InfoJetSoft.Service.Entity.Form frm, InfoJetSoft.Service.Entity.DataSPListAdapter adapter )
		{
			this.form = frm;
			this.spListAdapter = (InfoJetSoft.Service.Entity.DataSPListAdapter)DataAdapterTableUtil.getCurrentAdapter( this.form, adapter );
		}

		public string SiteUrl 
		{ 
			get
			{
				return this.spListAdapter.SiteUrl;
			}
		}

		public bool QueryAllowed 
		{ 
			get
			{
				return this.spListAdapter.QueryAllowed;
			}
		}

		public bool SubmitAllowed 
		{ 
			get
			{
				return this.spListAdapter.SubmitAllowed;
			}
		}

		public string Name 
		{ 
			get
			{
				return this.spListAdapter.Name;
			}
		}

		public void Query()
		{
			InfoJetSoft.Service.Entity.DataSPListAdapter templateAdapter = (InfoJetSoft.Service.Entity.DataSPListAdapter) DataAdapterTableUtil.getTemplateAdapter( this.form, this.spListAdapter );
			if( this.spListAdapter.QueryAllowed )
			{
				foreach( InfoJetSoft.Service.Entity.DataObject dataObject in this.form.Manifest.DataObjectList )
				{
					if( dataObject.SPListAdapter != null && dataObject.SPListAdapter.Equals( templateAdapter ) )
					{
						DataObjectSPLoadWorker.loadSPDataObject( this.form, dataObject, this.spListAdapter );
						return;
					}
				}
			}
		}

		//Unsupported.
		public void Submit()
		{
		
		}

	}
}
